package com.cloud.adrian.novel.author.config;

import com.cloud.adrian.novel.common.constant.ApiRouterConstants;
import com.cloud.adrian.novel.config.interceptor.TokenParseInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 作家门户-拦截器
 * @Author: xiangguiliang
 * @version: 1.0
 * @since: 2024/05/30
 */
@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {
    private final AuthInterceptor authInterceptor;
    private final TokenParseInterceptor tokenInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 权限认证拦截
        registry.addInterceptor(authInterceptor)
                .addPathPatterns(ApiRouterConstants.API_AUTHOR_URL_PREFIX + "/**")
                .excludePathPatterns(ApiRouterConstants.API_AUTHOR_URL_PREFIX + "/register",
                        ApiRouterConstants.API_AUTHOR_URL_PREFIX + "/status").order(2);

        // token解析
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns(ApiRouterConstants.API_AUTHOR_URL_PREFIX + "/register",
                        ApiRouterConstants.API_AUTHOR_URL_PREFIX + "/status").order(3);
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
